﻿// Copyright: 2012 
// Author: Minh Vu - YoungJ
// File name: FeedItem.cs
// Solution: WindowsPhoneRssReader
// Project: WindowsPhoneRssReader
// Time: 12:48 PM 07/05/2012

using System;
using System.Windows;
using WindowsPhoneRssReader.Utils;

namespace WindowsPhoneRssReader.Models
{
    public class FeedItem : MyBase
    {
        private string _title;
        public string Title
        {
            get { return _title; }
            set
            {
                if (string.IsNullOrEmpty(value)) return;
                _title = value;
                NotifyPropertyChanged("Title");
            }
        }

        private bool _favourite;
        public bool Favourite
        {
            get { return _favourite; }
            set
            {
                if (_favourite == value) return;
                Read = false;
                _favourite = value;
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                              {
                                                                  if (ParentFeed == null) return;
                                                                  ParentFeed.ParentModel.UpdateFavourites();
                                                                  XmlAction.UpdateFavouriteFeedItem(this);
                                                              });

                NotifyPropertyChanged("Favourite");
            }
        }

        private bool _read;
        public bool Read
        {
            get { return _read; }
            set
            {
                if (Favourite) return;
                if (Read == value) return;
                _read = value;
                NotifyPropertyChanged("Read");
                if (ParentFeed != null)
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                                  {
                                                                      XmlAction.UpdateReadFeedItem(this);
                                                                      ParentFeed.ParentModel.UnreadItems.Remove(this);
                                                                  });
            }
        }

        private Feed _parentFeed;
        public Feed ParentFeed
        {
            get { return _parentFeed; }
            set
            {
                if (value == null) return;
                _parentFeed = value;
                NotifyPropertyChanged("ParentFeed");
            }
        }

        private string _description;
        public string Description
        {
            get { return _description; }
            set
            {
                if (string.IsNullOrEmpty(value)) return;
                _description = value;
                NotifyPropertyChanged("Description");
            }
        }

        private string _url;
        public string Url
        {
            get { return _url; }
            set
            {
                if (string.IsNullOrEmpty(value)) return;
                _url = value;
                NotifyPropertyChanged("Url");
            }
        }

        private DateTime _datePublished;
        public DateTime DatePublished
        {
            get { return _datePublished; }
            set
            {
                _datePublished = value;
                NotifyPropertyChanged("DatePublished");
            }
        }
    }
}